package com.cuitrip.business.home.travel.ui;

import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.TextView;

import com.cuitrip.app.base.RecycleViewHolder;
import com.cuitrip.business.home.travel.model.FilterInfo;
import com.cuitrip.component.AutoMatchListView;
import com.cuitrip.service.R;
import com.lab.utils.ToastUtil;

import java.util.List;

import butterknife.Bind;

/**
 * 筛选列表的item
 * Created by ak
 */
public class FilterInfoViewHolder extends RecycleViewHolder<FilterInfo> {
    public static int RES = R.layout.filter_item;
    @Bind(R.id.filter_title)
    public TextView mFilterTitle;
    @Bind(R.id.filter_list)
    public AutoMatchListView mFilterListView;

    FilterInfo filterInfo;

    public FilterInfoViewHolder(View itemView) {
        super(itemView);

    }

    @Override
    public void render(FilterInfo filterInfo) {
        this.filterInfo = filterInfo;
        mFilterTitle.setText(filterInfo.getDesc());
        doMultiSelect(mFilterListView,null,filterInfo,null);
    }

    private void doMultiSelect(final AutoMatchListView listView, String[] selectIds, FilterInfo filterInfo, String[] selectedValues) {

        final List<FilterInfo.ValueInfo> valueInfoList = filterInfo.getShowValues();
        final TravelTripFilterAdapter adapter=new TravelTripFilterAdapter(listView,valueInfoList);
        listView.setAdapter(adapter);
        listView.setChoiceMode(filterInfo.getChoiceMode());

        for (int i = 0; i < valueInfoList.size();i++){
            FilterInfo.ValueInfo valueInfo = valueInfoList.get(i);
            listView.setItemChecked(i,valueInfo.isSelected());
        }
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                adapter.notifyDataSetChanged();
            }
        });

    }
}
